package cn.chengpengper.shortlink.repository.impl;

import cn.chengpengper.shortlink.mapper.AccountMapper;
import cn.chengpengper.shortlink.model.AccountDO;
import cn.chengpengper.shortlink.repository.AccountRepository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <p>
 * Mapper 接口实现
 * </p>
 *
 * @author huchengpeng
 * @since 2023-08-20
 */
@Slf4j
@Component
public class AccountRepositoryImpl implements AccountRepository {

    @Autowired
    private AccountMapper accountMapper;

    @Override
    public int insert(AccountDO accountDO) {
        return accountMapper.insert(accountDO);
    }

    @Override
    public AccountDO findByPhone(String phone) {
        LambdaQueryWrapper<AccountDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AccountDO::getPhone, phone);

        return accountMapper.selectOne(queryWrapper);
    }
}
